package cn.webrx;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class BufferedStream1 {
    public static void main(String[] args) {
        try (
                FileInputStream fis = new FileInputStream("d:/abc/g1.jpg");
                FileOutputStream fos = new FileOutputStream("g1.jpg");
                BufferedInputStream bis = new BufferedInputStream(fis);
                BufferedOutputStream bos = new BufferedOutputStream(fos);
        ) {
            long ss = System.currentTimeMillis();
            int b = 0;
            while ((b = fis.read()) != -1) {
                fos.write(b);
            }
            long ee = System.currentTimeMillis();
            System.out.println(ee - ss);
            System.out.println("----------------");

            ss = System.currentTimeMillis();
            b = 0;
            while ((b = bis.read()) != -1) {
                bos.write(b);
            }
            ee = System.currentTimeMillis();
            System.out.println(ee - ss);


            System.out.println("----------------");
            ss = System.currentTimeMillis();
            byte[] buf = new byte[102400];
            int len = 0;
            while ((len = fis.read(buf)) != -1) {
                fos.write(buf, 0, len);
            }
            ee = System.currentTimeMillis();
            System.out.println(ee - ss);
        } catch (Exception e) {

        }
    }
}
